﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/AdminSite.Master" Inherits="System.Web.Mvc.ViewPage<Veteran_cms.Models.menu>" %>
<%@ Import Namespace="Veteran_cms.Models" %>


<asp:Content ID="Content2" ContentPlaceHolderID="TitleAreaPlaceHolder" runat="server">
    <div class="pageTitle">
        <h5>Quản lý trang mục dịch vụ</h5>
        <span>Trang quản lý chi tiết nội về Menu và Sub Menu</span>
    </div>
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContentPlaceHolder" runat="server">

    <%using (Html.BeginForm("Details", "ManageMenu", new { id = Model.menu_id }, FormMethod.Post, new { enctype = "multipart/form-data", @class = "form", id = "validate" }))
      { %> 
      <fieldset>
      
   
        <div class="widget">
      <div style="float:right"><a href="<%=Url.Action("IndexMenu","ManageMenu") %>" title="" class="backTo" style="margin: 5px;"><img src="../../images/adminSite/icons/prev.png" alt="" class="icon" /><span>Trở về</span></a></div>
            <div class="title"><img src="../../images/adminSite/icons/dark/pencil.png" alt="" class="titleIcon" /><h6>Thông tin chi tiết về Menu</h6></div>
            <div class="formRow">
                <label>Menu:<span class="req">*</span></label>
                <div class="formRight"><%:Html.TextBoxFor(model => model.name, new { @class = "validate[required]", id = "req" })%></div>
                <div class="clear"></div>
            </div>
            <div class="formRow">
                <label>Diễn giải/ Sơ lượt:<span class="req">*</span></label>
                <div class="formRight"><%:Html.TextAreaFor(model => model.description, new { @class = "autoGrow", id = "textareaServiceDetail", rows = "8", cols = "" })%></div>
                <div class="clear"></div>
            </div>
            <div class="formSubmit"><input type="submit" value="cập nhật" class="blueB" /></div>
        <%}%>
        <%using (Html.BeginForm("Delete", "ManageMenu", new { id = Model.menu_id }, FormMethod.Post, new { enctype = "multipart/form-data", @class = "form", id = "validate" }))
        { %>
            <div class="formSubmit"><input type="submit" value="Xóa" class="redB" onclick="return ConfirmDelete()"/></div>
            <div class="clear"></div>
            <div><%:Html.HiddenFor(model => model.menu_id)%></div>
        <%} %>
            <div class="clear"></div>
        </div>
        <%if (ViewData["Msg"] != null)
          {%>
        <div class="nNote nSuccess hideit">
            <p><strong><%=ViewData["Msg"]%></strong></p>
        </div>
        <%} %>
        <div class="widget">
            <div class="title"><span class="titleIcon"><input type="checkbox" id="titleCheck" name="titleCheck" /></span>
                <h6>Danh sách Sub Menu</h6>
                <div style="float:right"><a href="<%=Url.Action("CreateMenuItem","ManageMenu", new {menu_id = Model.menu_id}) %>" title="" class="button greyishB" style="margin: 5px;"><img src="../../images/adminSite/icons/light/create.png" alt="" class="icon" /><span>Thêm mới Sub Menu</span></a></div>
            </div>
            <table cellpadding="0" cellspacing="0" width="100%" class="sTable withCheck mTable" id="checkAll">
                <thead>
                    <tr>
                        <td><img src="../../images/adminSite/icons/tableArrows.png" alt="" /></td>
                        <td >Tên hiển thị</td>
                        <td>Thuộc Menu</td>
                        <td>Liên kết</td>
                        <td>Chức năng</td>
                    </tr>
                </thead>
                
                <tbody>
                <%
                    
                    Veterandb ctx = new Veterandb();
                if (Model != null)
                {
                    int CountId = 0;
                    menu_item mn = new menu_item();
                        List<menu_item> ctg = ctx.menu_item.ToList();
                        ctg.Insert(0, mn);
                    var menuModel=new HomeAdminListViewModel();
                    menuModel.MenuItemList=ctx.menu_item.Where(p=>p.menu_id==Model.menu_id).OrderBy(p=>p.sort_order).ToList();
                    foreach (var item in menuModel.MenuItemList)
                    {
                        CountId++;
                        ViewData[CountId.ToString()] = new SelectList(ctg.AsEnumerable<menu_item>(), "menu_item_id", "label", item.parent_id);   
                        %>   
            
                        <tr>
                            <td><input type="checkbox" id="titleCheck2" name="checkRow" /></td>
                            <td style="margin-right:20px"><div class="formRow"><%=Html.TextBox("label", item.label, new { @class = "validate[required]", id = "name" + CountId })%></div></td>
                            <td style="width:10px"><%=Html.DropDownList(item.menu.name.ToString(), ViewData[CountId.ToString()] as SelectList, new { id="ddl"+CountId})%></td>
                            <td><div class="formRow"><%=Html.TextBox("link",item.link, new { @class = "validate[required]", id = "lnk" + CountId })%></div></td>
                            <td class="actBtns">
                                <a href="#" title="Cập nhật" class="tipS" id="txtUpdateAttribute" onclick="UpdateMenuItem(<%=item.menu_item_id %>, <%=CountId %>)">
                                    <img src="../../images/adminSite/icons/dark/pencil.png" alt="" /></a>
                                <a href="<%=Url.Action("DeleteMenuItem", "ManageMenu", new {id = item.menu_item_id}) %>" title="Xóa" class="tipS">
                                    <img src="../../images/adminSite/icons/uploader/deleteFile.png" alt="" onclick="return ConfirmDeleteItem(<%=item.menu_item_id %>)"/></a>
                            </td>
                        </tr>
                    <%}
                }%>
                </tbody>
                <tfoot>
                    <tr>
                    <td colspan="4">
                            <div class="tPagination">
                                
                            </div>
                        </td>
                    </tr>
                </tfoot>
            </table>
        </div>     
    </fieldset>
    
    <script type="text/javascript">
        function UpdateMenuItem(id, countId) {
            var label = $('#name' + countId).val();
            var parentid = $("#ddl" + countId).val();
            var link = $('#lnk' + countId).val();
            $.post("/ManageMenu/UpdateToMenuItem", { parent_id: parentid, id: id, label: label, link: link });
        };

        function ConfirmDeleteItem(id) {
            var valueR = false;
            $.post("/ManageMenu/CheckExistParent", { id: id }, function (data) {
                if (data == "True") {
                    if (confirm("Tồn tại Sub Menu.Bạn chắc chắn xóa tất cả?") == true) {
                        valueR = true;
                    }
                    else
                        valueR = false;
                }
                else {
                    if (confirm("Bạn chắc chắn xóa?") == true) {
                        valueR = true;
                    }
                    else
                        valueR = false;
                }
               
            });
            return valueR;
           
      }
    </script>
</asp:Content>